package com.avantis.common.entity;

import com.avantis.common.entity.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName AdminUser
 * @Description TODO
 * @Author kirago
 * @Date 2018/11/26 19:09
 * @Version 1.0
 **/
@Entity
@Table(name = "k_adminuser")
@Data
public class AdminUser extends BaseEntity implements Serializable {

	@ApiModelProperty("员工姓名")
	@NotNull(message = "员工姓名是必填项!")
	@NotEmpty(message = "员工姓名是必填项!")
	@NotEmpty(message = "员工姓名不能为空!")
	@Column(unique = true,nullable = false)
	private String username;

	@ApiModelProperty("工号")
	@NotNull(message = "工号是必填项!")
	@NotEmpty(message = "工号是必填项!")
	@NotEmpty(message = "工号不能为空!")
	@Column(unique = true,nullable = false)
	private String jobNumber;

	@ApiModelProperty("所属门店")
	@NotNull(message = "所属门店是必填项!")
	@NotEmpty(message = "所属门店是必填项!")
	@NotEmpty(message = "所属门店不能为空!")
	@Column
	private String orgName;

	//默认为0.男性
	@Column(nullable = false)
	private Integer sex = 0;

	@ApiModelProperty("密码")
	@NotNull(message = "密码是必填项!")
	@NotEmpty(message = "密码是必填项!")
	@NotEmpty(message = "密码不能为空!")
	@Column(nullable = false)
	private String password;

	private String originalPassword;

	@ApiModelProperty("手机号")
	@NotNull(message = "手机号是必填项!")
	@NotEmpty(message = "手机号是必填项!")
	@NotEmpty(message = "手机号不能为空!")
	@Column(unique = true,nullable = false)
	private String phone;

	@ApiModelProperty("邮箱")
	@NotNull(message = "邮箱是必填项!")
	@NotEmpty(message = "邮箱是必填项!")
	@NotEmpty(message = "邮箱不能为空!")
	@Column(unique = true,nullable = false)
	private String email;

	@Column
	private String address;

	//是否可以使用 0正常 1锁定
	@Column(nullable = false)
	private Integer enable = 0;

	@JsonIgnore
	@JoinTable(name = "k_adminuser_role",
			joinColumns = {@JoinColumn(name = "adminuser_id",referencedColumnName = "id")},
			inverseJoinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")})
	@ManyToMany(cascade = CascadeType.ALL)
	private Set<Role> roles = new HashSet<>();

	@JsonIgnore
	@JoinTable(name = "k_adminuser_price",
			joinColumns = {@JoinColumn(name = "adminuser_id",referencedColumnName = "id")},
			inverseJoinColumns = {@JoinColumn(name = "price_id",referencedColumnName = "id")})
	@ManyToMany(cascade = CascadeType.ALL)
	private Set<Price> prices = new HashSet<>();

	@JsonIgnore
	@JoinTable(name = "k_adminuser_warehouse",
			joinColumns = {@JoinColumn(name = "adminuser_id",referencedColumnName = "id")},
			inverseJoinColumns = {@JoinColumn(name = "warehouse_id",referencedColumnName = "id")})
	@ManyToMany(cascade = CascadeType.ALL)
	private Set<WareHouse> warehouses = new HashSet<>();

	@JsonIgnore
	@JoinTable(name = "k_adminuser_bill",
			joinColumns = {@JoinColumn(name = "adminuser_id",referencedColumnName = "id")},
			inverseJoinColumns = {@JoinColumn(name = "bill_id",referencedColumnName = "id")})
	@ManyToMany(cascade = CascadeType.ALL)
	private Set<Bill> bills = new HashSet<>();

}
